home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / othergnu / texinf~1.zoo / texinfo.st / texi2roff / texi2roff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-12  |  3.0 KB  |  148 lines

  1. /*
  2.  * texi2roff.c - texi2roff mainline
  3.  *         Release 1.0a     August 1988
  4.  *        Release 2.0    January 1990
  5.  *
  6.  * Copyright 1988, 1989, 1990  Beverly A.Erlebacher
  7.  * erlebach@cs.toronto.edu    ...uunet!utai!erlebach
  8.  *
  9.  */
  10.  
  11. #include <stdio.h>
  12. #ifndef __TURBOC__
  13. #include <sys/types.h>
  14. #endif
  15. #include <sys/stat.h>
  16. #include "texi2roff.h"
  17.  
  18. char *progname;
  19. int transparent = NO;    /* for -t flag */
  20.  
  21. /*
  22.  * main - parse arguments, handle options
  23.  *    - initialize tables and other strings
  24.  *     - open files and pass them to process().
  25.  */
  26. main(argc, argv)
  27. int argc;
  28. char *argv[];
  29. {
  30.     int c, errflg = 0;
  31.     FILE *in;
  32.     char *inname;
  33.     int macropkg = NONE;    /* user's choice of MS, ME or MM */
  34.     int showInfo = NO;         /* -I : display Info file material?*/
  35.     int makeindex = NO;     /* -i : to emit index macros? */
  36.  
  37.     extern int optind;
  38.     extern char *optarg;
  39.     extern int process();
  40.     extern void initialize();
  41.  
  42.     progname = argv[0];
  43.  
  44.     while ((c = getopt(argc, argv, "itIm:--")) != EOF)
  45.     switch (c) {
  46.       case 'i':
  47.           makeindex  = YES;
  48.           break;
  49.       case 't':
  50.           transparent = YES;
  51.           break;
  52.     case 'I':
  53.         showInfo = YES;
  54.         break;
  55.     case 'm':
  56.         if (macropkg != NONE) {
  57.         errflg++;
  58.         } else {
  59.         switch ( (char) *optarg) {
  60.         case 's':
  61.             macropkg = MS;
  62.             break;
  63.         case 'm':
  64.             macropkg = MM;
  65.             break;
  66.         case 'e':
  67.             macropkg = ME;
  68.             break;
  69.         default:
  70.             errflg++;
  71.             break;
  72.         }
  73.         }
  74.         break;
  75.     case '?':
  76.         errflg++;
  77.         break;
  78.     }
  79.  
  80.     if (macropkg == NONE) {
  81.     errflg++;
  82.     }
  83.     if (errflg) {
  84.     (void) fprintf(stderr,
  85.         "Usage: %s [ -me -mm -ms ] [ -iIt ] [ file ... ]\n", progname);
  86.     exit(1);
  87.     }
  88.  
  89.     (void) initialize(macropkg, showInfo, makeindex);
  90.  
  91.     if (optind >= argc) {
  92.     errflg += process(stdin, "stdin");
  93.     }
  94.     else
  95.     for (; optind < argc; optind++) {
  96.         if (STREQ(argv[optind], "-")) {
  97.         inname = "stdin";
  98.         in = stdin;
  99.         }
  100.         else {
  101.         if (( in = fopen(argv[optind], "r")) == NULL) {
  102.             (void) fprintf(stderr,"%s : can't open file %s\n",
  103.                 progname, argv[optind]);
  104.             continue;
  105.         }
  106.         inname = argv[optind];
  107.         }
  108.         errflg += process(in, inname);
  109.         if (in != stdin)
  110.         (void) fclose(in);
  111.     }
  112.     exit(errflg);
  113. }
  114.  
  115. /*
  116.  * process -  check opened files and pass them to translate().
  117.  *       -  report on disastrous translation failures
  118.  */
  119. int
  120. process(fp, filename)
  121.     FILE *fp;
  122.     char *filename;
  123. {
  124.     struct stat statbuf;
  125.     extern int translate(/* FILE *, char * */);
  126.  
  127.     if (fstat(fileno(fp), &statbuf) != 0){
  128.     (void) fprintf(stderr,"%s : can't fstat file %s\n", progname, 
  129.                                 filename);
  130.     return 1;
  131.     }
  132.     if ((statbuf.st_mode & S_IFMT)==S_IFDIR) {
  133.     (void) fprintf(stderr, "%s : %s is a directory\n", progname,
  134.                                 filename);
  135.     return 1;
  136.     }
  137.     /* translate returns 0 (ok) or -1 (disaster). it isn't worthwhile
  138.      * to try to recover from a disaster.
  139.      */
  140.     if (translate(fp, filename) < 0) {
  141.     (void) fprintf(stderr,
  142.         "%s: error while processing file %s, translation aborted\n",
  143.         progname, filename);
  144.     exit(1); 
  145.     }
  146.     return 0;
  147. }
  148.